local jixu = fk.CreateSkill {

  name = "joy__jixu",

  tags = {  },

}



jixu:addEffect("active", {
  name = "joy__jixu",
  anim_type = "control",
  card_num = 0,
  min_target_num = 1,
  max_target_num = 4,
  can_use = function(self, player)
    return player:usedSkillTimes(jixu.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected)
      return to_select ~= player.id
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    room:sortPlayersByAction(effect.tos)
    local targets = table.map(effect.tos, function(id) return room:getPlayerById(id) end)
    for _, p in ipairs(targets) do
      local choices = {"yes", "no"}
      p.request_data = json.encode({choices, choices, jixu.name, "#jixu-choice:"..player.id})
    end
    room:notifyMoveFocus(room.alive_players, jixu.name)
    room:doBroadcastRequest("AskForChoice", targets)
    for _, p in ipairs(targets) do
      local choice
      if p.reply_ready then
        choice = p.client_reply
      else
        p.client_reply = "yes"
        choice = "yes"
      end
      room:sendLog{
        type = "#jixu-quest",
        from = p.id,
        arg = choice,
      }
    end
    local right = table.find(player.player_cards[Player.Hand], function(id)
      return Fk:getCardById(id).trueName == "slash" end) and "yes" or "no"
    local n = 1
    local wrong = {}
    for _, p in ipairs(targets) do
      local choice = p.client_reply
      if choice ~= right then
        room:doIndicate(player.id, {p.id})
        if not p:isNude() then
          local id = room:askForCardChosen(player, p, "he", jixu.name)
          room:throwCard({id}, jixu.name, p, player)
        end
        if not p.dead then
          room:useVirtualCard("slash", nil, player, p, jixu.name, true)
        end
      else 
        n = n + 1
      end
    end
    if n > 0 and not player.dead then
      player:drawCards(n, jixu.name)
      room:addPlayerMark(player,"joy__jixu-turn",n)
    end
  end,
})

jixu:addEffect("maxcards", {
  name = "#joy__jixu_maxcards",
  correct_func = function(self, player)
    return player:getMark("joy__jixu-turn")
  end,
})

return jixu